import { CacheModule, Global, Module } from '@nestjs/common';
import * as redisStore from 'cache-manager-redis-store';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { RedisService } from './redis.service';

@Global()
@Module({
    imports : [
        CacheModule.registerAsync({
            imports: [ConfigModule],
            inject : [ConfigService],
            useFactory : async (configService : ConfigService) => {
                return {
                store : redisStore,
                parse : false,
                ...configService.get('redis')
                }
            }
        })
    ],
    providers: [RedisService],
    exports : [RedisService]
})
export class RedisModule {}
